package it.fantacalcio.struts.action.user.classifica;

import java.util.ArrayList;
import java.util.List;

import it.fantacalcio.model.Classifica;
import it.fantacalcio.model.User;
import it.fantacalcio.spring.service.MyServiceFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class PrepareClassificaAction extends Action {
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		User userInSession = (User) request.getSession().getAttribute("userInSession");
		if(userInSession==null || userInSession.getAttivo().equals("NO")){
			return mapping.findForward("noninsession");
		}
		
		List<Classifica> listaClassifica = new ArrayList<Classifica>();
		try {
			listaClassifica = MyServiceFactory.getClassificaService().list();
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("error");
		}
		request.setAttribute("listaClassifica", listaClassifica.size() == 0 ? null : listaClassifica);
		return mapping.findForward("lista");
	}
}
